# -*- coding: utf-8 -*-
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from datetime import timedelta
from jms.dwd.oms.dwd_yl_oms_oms_waybill_incre_dt import jms_dwd__dwd_yl_oms_oms_waybill_incre_dt
from jms.dim.dim_mysql_lmdm_sys_second_code import jms_dim__dim_mysql_lmdm_sys_second_code
from jms.dim.dim_mysql_lmdm_sys_tail_dispatch_area import jms_dim__dim_mysql_lmdm_sys_tail_dispatch_area
from jms.dim.dim_mysql_lmdm_sys_tail_dispatch_area_staff import jms_dim__dim_mysql_lmdm_sys_tail_dispatch_area_staff


jms_dm__cn_address_warehouse_day_rule_dt_parquet = SparkSqlOperator(
    task_id='jms_dm__cn_address_warehouse_day_rule_dt_parquet',
    task_concurrency=1,
    pool_slots=2,
    master='yarn',
    execution_timeout=timedelta(minutes=60),
    email=['yushuo@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dm__cn_address_warehouse_day_rule_dt_parquet_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dm/cn_address_warehouse_day_rule_dt_parquet/execute.hql',
    yarn_queue='pro',
    executor_cores=2,
    executor_memory='8G',
    driver_memory='4G',
    driver_cores=2,
    num_executors=16,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={
        'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
        'spark.shuffle.service.enabled' : 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors' : 20,  # 动态资源最大扩容 Executor 数
        'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
        'spark.sql.sources.partitionOverwriteMode' : 'dynamic',  # 允许删改已存在的分区
        'spark.executor.memoryOverhead' : '2G',  # 堆外内存
        'spark.sql.shuffle.partitions' : 200,
    },

)


jms_dm__cn_address_warehouse_day_rule_dt_parquet << [
    jms_dwd__dwd_yl_oms_oms_waybill_incre_dt,
    jms_dim__dim_mysql_lmdm_sys_second_code,
    jms_dim__dim_mysql_lmdm_sys_tail_dispatch_area,
    jms_dim__dim_mysql_lmdm_sys_tail_dispatch_area_staff
]